package com.catersystem.zmy.catersystem.utils;

import android.content.Context;
import android.media.AudioManager;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.media.SoundPool;
import android.net.Uri;

import com.catersystem.zmy.catersystem.R;

/**
 * 音效播放封装类
 * Created by Administrator on 2017/11/1 0001.
 */

public class SoundPlayUtils {
    // SoundPool对象
    public static SoundPool mSoundPlayer = new SoundPool(1,
            AudioManager.STREAM_SYSTEM, 5);
    public static SoundPlayUtils soundPlayUtils;
    // 上下文
    static Context mContext;

    /**
     * 初始化
     *
     * @param context
     */
    public static SoundPlayUtils init(Context context) {
        if (soundPlayUtils == null) {
            soundPlayUtils = new SoundPlayUtils();
        }

        // 初始化声音
        mContext = context;
        mSoundPlayer.load(mContext, R.raw.f, 1);// 6
        return soundPlayUtils;
    }

    /**
     * 播放声音
     */
    public void play() {
        mSoundPlayer.play(1, 1, 1, 0, 0, 1);
    }
    public void stop(){
        mSoundPlayer.stop(1);
    }
}
